﻿#ifndef EQUATION_H
#define EQUATION_H

#include <vector>
#include "sentence.h"

class NCA_EXPORT Expression : public std::vector<Sentence>
  {
  friend class ExpressionTest;
  public:
    Expression();
    ~Expression();
    bool operator== (const Expression &other) const;

    Word &wordAt(QPair<int, int> position);
    Word const &wordAt(QPair<int, int> position) const;

    void concatenate(Expression* other);   /*< appends other expression after this one, concatenating the two of them.*/
    void subExpression(int startingSentence, int startingWord, int wordCount, Expression &sub) const;

    void copyExpressionToMe(Expression *newE, int i); /*< inserts newS at specified index */

    bool groupTypes();
    bool doDeltaTricks();
    bool sameSentencesArithmetic();
    bool multiplyAllBrackets();

    void removeWords(int startingSentence, int startingWord, int wordCount);
    void insertIntoSentence(int startingSentence, int startingWord, const Expression &expression); /*< inserts expression at exact specified location*/
    void applyLabelDictionary(const QMap<QString, QStringList> &dict); /*< Replaces labels according to dictionary */

    int countWordType(Word::Type type) const;
    int countWords() const;
    void multiplyWith(Expression * other, Expression &result) const; /*< performs this*other. Order matters! Returns result of multiplication in a new object. */
    void multiplyByNumber(int n);

    void sort(); // sorts sentences in expression

    bool factorOutWhatYouCan();

  private:
    bool factorOutType(Word::Type type);
    bool factorOutCommonSentence();

    static bool sentenceLessThan(const Sentence &s1, const Sentence &s2);
  };

Q_DECLARE_METATYPE(Expression)

#endif // EQUATION_H
